package edu.tyut.game.ui.user.password

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.os.UserHandle
import android.widget.Button
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
import androidx.lifecycle.switchMap
import edu.tyut.game.R
import edu.tyut.game.logic.MailRepository
import edu.tyut.game.logic.UserRepository
import edu.tyut.game.logic.model.User
import edu.tyut.game.utils.LogUtils

class ForgetPasswordViewModel : ViewModel() {

    private val tag = "ForgetPasswordViewModel"

    lateinit var user: User

    // 找回密码的用户
    private val retrievePasswordUserLiveData = MutableLiveData<String>()
    val retrievePasswordUser = retrievePasswordUserLiveData.switchMap {
        UserRepository.getUser(it)
    }

    fun getUser(username: String) {
        LogUtils.d(tag, "getUser")
        retrievePasswordUserLiveData.value = username
    }

    // 邮件发送验证码
    private val sendMailLiveData = MutableLiveData<User>()
    val sendMailData = sendMailLiveData.switchMap {
        MailRepository.sendRetrievePasswordEmail(it)
    }

    fun sendRetrievePasswordEmail(user: User) {
        sendMailLiveData.value = user
    }
}